package lec07datastructure.v2;

public class MyDeque {
    int[] data = new int[100];
    int head = data.length / 2;
    int tail = head - 1;

    public static void main(String[] args) {
        MyDeque q = new MyDeque();
        for (int i = 0; i < 10; i++) {
            q.pushBack(i);
        }
        while (q.size() > 0) {
            System.out.println(q.front());
            q.popFirst();
        }
    }

    //data[head,tail]
    void pushBack(int x) {
        data[++tail] = x;
    }

    void pushFirst(int x) {
        data[--head] = x;
    }

    void popFirst() {
        ++head;
    }

    void popLast() {
        --tail;
    }

    int front() {
        return data[head];
    }

    int back() {
        return data[tail];
    }

    int size() {
        return tail - head + 1;
    }

    int get(int x) {
        return data[x + head];
    }
}
